import os
import sys

def download(LibcNameList):
    for item in LibcNameList:
        os.system("./download {}".format(item))
def download_old(LibcNameList):
    for item in LibcNameList:
        os.system("./download_old {}".format(item))

def mkDir(name):
    for item in name:
        os.system("mkdir -p ~/.local/glibc/{}/64/lib/".format(item))
        os.system("mkdir -p ~/.local/glibc/{}/32/lib/".format(item))

def getName(LibcNameList):
    name=[]
    for item in LibcNameList:
        print(item)
        if item.split("-")[0] in name or item.split("-")[0]=="" :
            continue
        else:
            name.append(item.split("-")[0])
    print("name:",name)
    return name

os.system("python3.6 /update_list")

f=open("./list","r")
content=f.read()

print(content)
LibcNameList=content.split("\n")

name=getName(LibcNameList)
mkDir(name)


download(LibcNameList)

iter_name = []
for LibcName in LibcNameList:
    if ((LibcName.split("-")[0]+"amd64") in iter_name) or (LibcName.split("-")[0]=="") :
        continue
    else:
        os.system("cp ./libs/{}/* ~/.local/glibc/{}/64/lib/".format(LibcName,LibcName.split("-")[0]))
        iter_name.append(LibcName.split("-")[0]+"amd64")
    if ((LibcName.split("-")[0]+"i386") in iter_name) or (LibcName.split("-")[0]=="") :
        continue
    else:
        os.system("cp ./libs/{}/* ~/.local/glibc/{}/32/lib/".format(LibcName,LibcName.split("-")[0]))
        iter_name.append(LibcName.split("-")[0]+"i386")



os.system("python3.6 /update_list")

f=open("./old_list","r")
content=f.read()

print(content)
LibcNameList=content.split("\n")

name=getName(LibcNameList)
mkDir(name)


download_old(LibcNameList)

iter_name = []
for LibcName in LibcNameList:
    if ((LibcName.split("-")[0]+"amd64") in iter_name) or (LibcName.split("-")[0]=="") :
        continue
    else:
        os.system("cp ./libs/{}/* ~/.local/glibc/{}/64/lib/".format(LibcName,LibcName.split("-")[0]))
        iter_name.append(LibcName.split("-")[0]+"amd64")
    if ((LibcName.split("-")[0]+"i386") in iter_name) or (LibcName.split("-")[0]=="") :
        continue
    else:
        os.system("cp ./libs/{}/* ~/.local/glibc/{}/32/lib/".format(LibcName,LibcName.split("-")[0]))
        iter_name.append(LibcName.split("-")[0]+"i386")
